package com.wsy.entity;
 
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.annotation.IdType;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;


@Data
@AllArgsConstructor
@NoArgsConstructor
 @TableName
public class Emp implements UserDetails {
@TableId(type = IdType.AUTO)
  private Integer empId;
  private String empUsername;
  private String empPwd;
  private Integer roleId;
  private Integer state;

  @TableField(exist = false)
  private String roleName;

    @TableField(exist = false)
    private Collection authorities;


    //获取权限
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.empPwd;
    }

    @Override
    public String getUsername() {
        return this.empUsername;
    }

    //用户是否过期
    @Override
    public boolean isAccountNonExpired() {
        return this.state!=1?true:false;
    }

    //用户是否被锁定
    @Override
    public boolean isAccountNonLocked() {
        return this.state!=2?true:false;
    }

    // 凭证是否过期:密码
    @Override
    public boolean isCredentialsNonExpired() {
        return this.state!=3?true:false;
    }

    // 是否启用
    @Override
    public boolean isEnabled() {
        return this.state!=4?true:false;
    }

}
